package logic

import (
	"context"
	"house/houseclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseImageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateHouseImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseImageLogic {
	return &CreateHouseImageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateHouseImageLogic) CreateHouseImage(req *types.CreateHouseImageRequest) (resp *types.Response, err error) {
	// todo: 房源图片发布
	image, err := l.svcCtx.HouseRpc.CreateHouseImage(l.ctx, &houseclient.CreateHouseImageReq{
		Title:   req.Title,
		Image:   req.Image,
		HouseId: req.HouseId,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "房源图片添加成功",
		Data: image,
	}, nil
}
